package com.taptech.doufu.ui.viewholder.personalcenter;


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.MineAbstractBean;
import com.taptech.doufu.bean.UserBean;
import com.taptech.doufu.bean.cartoon.CartoonBean;
import com.taptech.doufu.services.CartoonServices;
import com.taptech.doufu.util.GlideUtil;
import com.taptech.doufu.util.StringUtil;
import com.taptech.doufu.util.TMAnalysis;
import com.taptech.doufu.ui.view.drawcircle.BaseRecyclerViewViewHolder;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by longsiyang on 15/12/10.
 */
public class CartoonVerticalViewHolder<T extends CartoonBean> extends BaseRecyclerViewViewHolder implements View.OnClickListener
{

    // UI view
    protected View lay;
    protected ImageView ivPic;
    protected TextView tvTitle;
    protected TextView tvChapter;
    protected TextView tvDesc;
    protected TextView tvAuthorDesc;
    protected TextView tvScanCount;

    // Data
    T bean;


    public CartoonVerticalViewHolder(Context context, View itemView) {
        super(context, itemView);
        lay = itemView.findViewById(R.id.lay);
        ivPic =  itemView.findViewById(R.id.ivPic);
        tvTitle =  itemView.findViewById(R.id.tvTitle);
        tvChapter = itemView.findViewById(R.id.tvChapter);
        tvDesc =  itemView.findViewById(R.id.tvDesc);
        tvAuthorDesc =  itemView.findViewById(R.id.tvAuthorDesc);
        tvScanCount =  itemView.findViewById(R.id.tvScanCount);

    }

    @Override
    public void setViewHolderChildViewContent(MineAbstractBean tempBean, int position)
    {
        bean = (T) tempBean;
        mPosition = position;
        if (bean == null) {
            return;
        }
        handleChildViewDisplay();

    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.lay:
                Map keyMap = new HashMap();
                keyMap.put("mId", bean.getId());
                keyMap.put("mPos", mPosition);
                TMAnalysis.event(mContext, "cartoon_item_click", keyMap);

                CartoonServices.enterCartoonDes(mContext, bean);
                break;
        }
    }

    protected void handleChildViewDisplay() {
        lay.setOnClickListener(this);
        if (bean.getImage() != null) {
            GlideUtil.displayRoundImage(mContext,ivPic,!TextUtils.isEmpty(bean.getImage_v())?bean.getImage_v():bean.getImage(),2);
        }
        if (bean.getTitle() != null) {
            tvTitle.setText(bean.getTitle());
        }
        if (bean.getIntro() != null) {
            tvDesc.setText(StringUtil.filterLineFeed(bean.getIntro()));
        }
        if (bean.getSection_num() != null) {
            tvChapter.setText(bean.getSection_num() + "话");
        }


        if (bean.getRead_times() != null) {
            tvScanCount.setText(bean.getRead_times());
        }

        UserBean userBean = bean.getUser();

        if (userBean != null) {
            if (userBean.getName() != null) {
                tvAuthorDesc.setText(userBean.getName());
            }
        }


    }
}
